﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using Gurucore.Framework.Core;

namespace Gurucore.Framework.Business
{
	public class BusinessServiceExtension : ExtensionBase
	{
		public override void Initialize(params object[] p_arrParam)
		{
			string sRootDir = Application.GetInstance().WorkingDirectory;
			string sConfigDir = sRootDir + Path.DirectorySeparatorChar + "Config";

			//load system's service factory
			ServiceFactory oSvcFactory = new ServiceFactory(
				sConfigDir + Path.DirectorySeparatorChar + "System" + Path.DirectorySeparatorChar + "Service.config");
			//load all module's datasource factory
			DirectoryInfo oDirInfo = new DirectoryInfo(sConfigDir);
			FileInfo[] arrFile = oDirInfo.GetFiles("Service.config", SearchOption.AllDirectories);
			foreach (FileInfo oFile in arrFile)
			{
				if (!oFile.Directory.Name.EndsWith("System"))
				{
					ServiceFactory oModuleDSFactory = new ServiceFactory(oFile.FullName);
					oSvcFactory.Merge(oModuleDSFactory);
				}
			}

			Application.GetInstance().SetGlobalSharedObject(oSvcFactory);
		}
	}
}
